﻿using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Client;

namespace TFSMailer.Classes
{
    public class Projects 
    {
        public Projects()
        {
        }


        public static ProjectInfo[] GetListAllProjects(TeamFoundationServer tfs)
        {
            ICommonStructureService structureService = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));
            return structureService.ListAllProjects();
        }

        public void GetGroupsInProject()
        {
        }

        public static TeamProject[] GetAllTeamProjects(VersionControlServer sourcecontrol,bool refresh)
        {
            return sourcecontrol.GetAllTeamProjects(false);
        }

        public Identity[] GetGroupsInTeamProject(TeamFoundationServer tfs, TeamProject teamProjects)
        {
                IGroupSecurityService sec = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService));
                return  sec.ListApplicationGroups(teamProjects.ArtifactUri.AbsoluteUri);
        }

        public Identity[] ReadIdentities(TeamFoundationServer tfs,Identity identity)
        {
            IGroupSecurityService sec = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService));
            return sec.ReadIdentities(SearchFactor.Sid, new string[] { identity.Sid }, QueryMembership.Expanded);
        }

        public Identity ReadIdentity(TeamFoundationServer tfs,string identitySid)
        {
            IGroupSecurityService sec = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService));
            return sec.ReadIdentity(SearchFactor.Sid, identitySid, QueryMembership.None);
        }
    }
}
